/**
 * This file is part of iSecurePasswords.
 *
 *   iSecurePasswords is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   iSecurePasswords is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with iSecurePasswords.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Author: Matthew MacGregor
 * Created: 2012
 * iSecurePasswords, copyright 2013 Sudolink, LLC
 * 
 */ 
package com.sudolink.io;

import com.sudolink.isp.app.Application;
import java.io.File;
import java.io.IOException;

/**
 *
 * @author matsu
 */
public class Store implements IStore {
    
    private final File path;
    private boolean shouldOverwrite = true;
    
    public Store( String path ) {
        this.path = new File( path );
    }
    
    public Store( File path ) {
        this.path = path;
    }
    
    @Override
    public void store(String data) throws IOException {

        if( !path.exists() || shouldOverwrite() ) {
            com.sudolink.io.FileUtils.writeStringToFile(data, path);
            Application.setDataVerificationSignature();
        } else {
            throw new IOException("The path exists and overwrite is not specified.");
        }

    }
    
    @Override
    public void shouldOverwrite(boolean overwrite ){
        shouldOverwrite = overwrite;
    }
    
    @Override
    public boolean shouldOverwrite() {
        return shouldOverwrite;
    }
}
